<template>
  <div class="page-container" v-loading="loading">
    <div class="add-wrap">
      <div class="header-section">
        <Breadcrumb :titles="titles"></Breadcrumb>
        <div class="project-part">
          <div class="project-part-title">楼宇信息</div>
        </div>

        <el-row>
          <el-col :span="6">
            <span>楼宇：</span>
            <span>{{ baseInfo.name }}</span>
          </el-col>

          <el-col :span="6">
            <span>所属园区：</span>
            <span>{{ name || baseInfo.parkName }}</span>
          </el-col>

          <el-col :span="6">
            <span>建筑面积(平方米)：</span>
            <span>{{ baseInfo.buildArea }}</span>
          </el-col>

          <el-col :span="6">
            <span>总可租面积(平方米)：</span>
            <span>{{ baseInfo.rentArea }}</span>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="6">
            <span>剩余可出租面积(平方米)：</span>
            <span
              v-if="
                baseInfo.rentArea &&
                tableData.length &&
                tableData[0].addMonthTotalArea
              "
            >
              {{
                baseInfo.rentArea -
                tableData[0].addMonthTotalArea
              }}
            </span>
          </el-col>

          <el-col :span="6">
            <span>资产类型：</span>
            <span>{{ baseInfo.type }}</span>
          </el-col>

          <el-col :span="6">
            <span>入驻企业数：</span>
            <span>{{ baseInfo.enterprise }}</span>
          </el-col>

          <el-col :span="6">
            <span>楼层说明：</span>
            <span>{{ baseInfo.explain }}</span>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="6">
            <span>责任单位：</span>
            <span>{{ baseInfo.unit }}</span>
          </el-col>

          <el-col :span="6">
            <span>是否参与考核：</span>
            <span>{{ baseInfo.checkFlag }}</span>
          </el-col>
        </el-row>
      </div>

      <!-- 入驻商家列表展示 -->
      <div class="project-part">
        <div class="project-part-title">入驻商家</div>
      </div>
      <div class="table-section mb-2">
        <el-table
          :data="baseInfo.enterpriseRelList || []"
          :header-cell-style="{
            background: '#F2F6FB',
            color: ' #6B767D'
          }"
          max-height="500"
        >
          <el-table-column
            label="商家名称"
            prop="name"
            show-overflow-tooltip
          />
          <el-table-column
            label="入驻楼层"
            prop="occupancyNum"
            show-overflow-tooltip
          />
          <el-table-column
            label="入驻面积（平方米）"
            prop="occupancyArea"
            show-overflow-tooltip
          />
          <el-table-column
            label="入驻时间"
            prop="occupancyTime"
            show-overflow-tooltip
          />
        </el-table>
      </div>

      <div class="project-part">
        <div class="project-part-title">载体去化</div>
      </div>
      <div class="table-section">
        <el-table
          :data="tableData"
          :header-cell-style="{
            background: '#F2F6FB',
            color: ' #6B767D'
          }"
          max-height="500"
        >
          <el-table-column
            label="年度"
            prop="year"
            show-overflow-tooltip
          />
          <el-table-column
            label="月份"
            prop="month"
            show-overflow-tooltip
          />
          <el-table-column
            label="本年度累计新增已去化面积(平方米)"
            prop="addMonthArea"
            show-overflow-tooltip
          />
          <el-table-column
            label="投用后累计已去化面积(平方米)"
            prop="addMonthTotalArea"
            show-overflow-tooltip
          />
          <el-table-column
            label="实际出租率(%)"
            prop=""
            show-overflow-tooltip
          >
            <template slot-scope="scope">
              <div
                v-if="
                  scope.row.addMonthTotalArea &&
                  baseInfo.rentArea
                "
              >
                {{
                  (
                    (Number(scope.row.addMonthTotalArea) /
                      Number(baseInfo.rentArea)) *
                    100
                  ).toFixed(2)
                }}
              </div>
            </template>
          </el-table-column>
        </el-table>
      </div>
    </div>
    <div class="line">
      <el-button @click="goList" class="save-btn"
        >返回</el-button
      >
    </div>
  </div>
</template>

<script>
import Breadcrumb from '@/components/breadcrumb'
import dayjs from 'dayjs'
import {
  queryCarrierInfoById,
  queryParkInfo
} from '@/api/dataManagement'

export default {
  props: {
    title: String,
    pkid: String,
    name: String
  },
  components: {
    Breadcrumb
  },
  data() {
    return {
      baseInfo: {},
      tableData: [],
      select: '',
      parkOptions: [],
      loading: false
    }
  },
  computed: {
    titles() {
      return [this.title]
    }
  },
  mounted() {
    const date = new Date()
    this.select = dayjs(date).format('YYYY-M')
    this.searchInfo()
  },
  methods: {
    async searchInfo() {
      this.loading = true
      const params = {
        pageIndex: 1,
        pageSize: 999
      }
      const result = await queryParkInfo(params)
      this.parkOptions = result.data.list
      await queryCarrierInfoById(this.pkid)
        .then((res) => {
          this.baseInfo = res.data
          this.baseInfo.parkName = this.parkOptions.find(
            (i) => i.pkid === this.baseInfo.parkId
          ).name
          this.tableData = res.data.monthRelList
          this.loading = false
        })
        .catch((err) => {
          this.$message.error(err)
          this.loading = false
        })
    },
    goList() {
      this.$router.push({
        path: '/dataManagement/carrierReduction/commercialVehicle/list'
      })
    }
  }
}
</script>

<style lang="scss" scoped>
@import '~@/assets/css/table.scss';
@import '~@/assets/css/form.scss';
.page-container {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.add-wrap {
  flex: 1;
  overflow: auto;
  padding: 10px 20px;

  .title {
    margin: 15px 0;
  }
}

// .header-section {
//   padding: 10px 20px;
//   flex-shrink: 0;

//   .title {
//     margin: 15px 0;
//   }
// }

.line {
  flex-shrink: 0;
  padding: 10px;
  background: #fff;
  border-top: 1px solid #eee;
  text-align: center;
}

.save-btn {
  background: #497fa3;
  border: 1px solid #497fa3;
  width: 104px;
  color: white;
  font-size: 14px;
  width: 104px;
  height: 34px;
  display: flex;
  justify-content: center;
  align-items: center;
  margin: 10px auto;
}

.el-row {
  margin-bottom: 10px;

  .el-col span:nth-of-type(2) {
    color: #7c7a7a;
  }
}

.mb-2 {
  margin-bottom: 16px;
}
</style>
